Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CMakeLists Targets for integration #1227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jbltx
Copy link

@jbltx jbltx commented Oct 31, 2019

I have just added some configuration in the src/CMakeLists.txt file to get a more user-friendly integration when using the API in other applications. The modifications are :

  • Remove the possibility to have different names for the library output (this is the workaround I have found to have a universal CMake targets file, see below)
  • Set the INCLUDE_DIR as a variable, depending on the CMake usage (BUILD/INSTALL)
  • Add EXPORT parameter on install command to generate OpenVRTargets.cmake
  • Add a new config file OpenVRConfig.cmake, including itself the generated OpenVRTargets.cmake file

Build:

git clone https://github.com/ValveSoftware/openvr.git
cd openvr && mkdir build && cd $_
cmake -DCMAKE_PREFIX_PATH=C:/api/OpenVR ..
cmake --build . --target all
cmake --build . --target install 

Output:

C:/api/OpenVR/cmake
C:/api/OpenVR/cmake/OpenVRConfig.cmake
C:/api/OpenVR/cmake/OpenVRConfigVersion.cmake
C:/api/OpenVR/cmake/OpenVRTargets-release.cmake
C:/api/OpenVR/cmake/OpenVRTargets.cmake
C:/api/OpenVR/include
C:/api/OpenVR/include/openvr
C:/api/OpenVR/include/openvr/openvr.h
C:/api/OpenVR/include/openvr/openvr_capi.h
C:/api/OpenVR/include/openvr/openvr_driver.h
C:/api/OpenVR/lib
C:/api/OpenVR/lib/openvr_api.lib

Integration:

find_package(OpenVR REQUIRED)
# We only need to link the library, include_dir is already set by CMake config file
target_link_libraries(myproject 
    PRIVATE OpenVR::openvr_api     # <-- namespace::targetName !
)

Notes

  • With this approach, we don't need a custom FindOpenVR.cmake file anymore.
  • Including the generated targets config file in OpenVRConfig.cmake instead of directly have the generated content in the file is for extensibility purposes, we can always overwrite things made by CMake.
  • I am not sure if set the library name as a constant openvr_api can break things in the workflow. It seems to be a huge change, but it makes life easier during integration, as the API has the same name, no matter the platform. Also in your distribution, the library for WIndows 64bits is not named openvr_api64 but openvr_api (see in lib/win64 and bin/win64 folder).

I am of course open to any change if you have better ideas to get a successful merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant